<template>
  <div>
    <h4>生产投料（前配）：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="beforeColumns"
      :dataSource="beforeList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="beforeDetail(record)">详情</a>
      </template>
    </a-table>
    <h4>生产投料（后配）：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="afterColumns"
      :dataSource="afterList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="afterDetail(record)">详情</a>
      </template>
    </a-table>
    <h4>包装投料：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="packageColumns"
      :dataSource="packageList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="packageDetail(record)">详情</a>
      </template>
    </a-table>
    <erp-production-feeding-before-modal ref="beforeForm" />
    <erp-production-feeding-after-modal ref="afterForm" />
    <erp-package-feeding-modal ref="packageForm" />
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import ErpProductionFeedingBeforeModal from '@/views/erp/feedingbefore/modules/ErpProductionFeedingBeforeModal.vue'
import ErpProductionFeedingAfterModal from '@/views/erp/feedingafter/modules/ErpProductionFeedingAfterModal.vue'
import ErpPackageFeedingModal from '@/views/erp/feedingpackage/modules/ErpPackageFeedingModal.vue'

export default {
  name: 'feeding',
  components: {
    ErpProductionFeedingBeforeModal,
    ErpProductionFeedingAfterModal,
    ErpPackageFeedingModal,
  },
  data() {
    return {
      description: '生产投料信息',
      beforeList: [],
      beforeColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '投料记录单号',
          align: 'center',
          dataIndex: 'feedingRecordCode',
        },
        {
          title: '单据类型',
          align: 'center',
          dataIndex: 'documentType_dictText',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '配方号',
          align: 'center',
          dataIndex: 'formulaNumber',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '执行日期',
          align: 'center',
          dataIndex: 'workTime',
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '操作时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      afterList: [],
      afterColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '投料记录单号',
          align: 'center',
          dataIndex: 'feedingRecordCode',
        },
        {
          title: '单据类型',
          align: 'center',
          dataIndex: 'documentType_dictText',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '配方号',
          align: 'center',
          dataIndex: 'formulaNumber',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '执行日期',
          align: 'center',
          dataIndex: 'workTime',
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '操作部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '操作时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      packageList: [],
      packageColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '投料记录单号',
          align: 'center',
          dataIndex: 'feedingRecordCode',
        },
        {
          title: '单据类型',
          align: 'center',
          dataIndex: 'documentType_dictText',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'materialSpec',
        },
        {
          title: '配方号',
          align: 'center',
          dataIndex: 'formulaNumber',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '包装车间',
          align: 'center',
          dataIndex: 'packshopCode_dictText',
        },
        {
          title: '执行日期',
          align: 'center',
          dataIndex: 'workTime',
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '操作部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '操作时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        before: '/feedingbefore/erpProductionFeedingBefore/allList',
        after: '/feedingafter/erpProductionFeedingAfter/allList',
        package: '/feedingpackage/erpPackageFeeding/allList',
      },
    }
  },

  methods: {
    loadFeedingData(batchNumber) {
      this.loadBeforeData(batchNumber)
      this.loadAfterData(batchNumber)
      this.loadPackageData(batchNumber)
    },
    loadBeforeData(batchNumber, convert) {
      this.beforeList = []
      if (batchNumber) {
        let params = { pageSize: 999, pageNo: 1 }
        if (convert) {
          params.planNumber = batchNumber
        } else {
          params.batchNumber = batchNumber
        }
        getAction(this.url.before, params).then((res) => {
          if (res.success) {
            this.beforeList = res.result.records || res.result || []
          }
        })
      }
    },
    loadAfterData(batchNumber, convert) {
      this.afterList = []
      if (batchNumber) {
        let params = { pageSize: 999, pageNo: 1 }
        if (convert) {
          params.planNumber = batchNumber
        } else {
          params.batchNumber = batchNumber
        }
        getAction(this.url.after, params).then((res) => {
          if (res.success) {
            this.afterList = res.result.records || res.result || []
          }
        })
      }
    },
    loadPackageData(batchNumber, convert) {
      this.packageList = []
      if (batchNumber) {
        let params = { pageSize: 999, pageNo: 1 }
        if (convert) {
          params.planNumber = batchNumber
        } else {
          params.batchNumber = batchNumber
        }
        getAction(this.url.package, params).then((res) => {
          if (res.success) {
            this.packageList = res.result.records || res.result || []
          }
        })
      }
    },
    beforeDetail: function (record) {
      this.$refs.beforeForm.edit(record)
      this.$refs.beforeForm.title = '详情'
      this.$refs.beforeForm.disableSubmit = true
    },
    afterDetail: function (record) {
      this.$refs.afterForm.edit(record)
      this.$refs.afterForm.title = '详情'
      this.$refs.afterForm.disableSubmit = true
    },
    packageDetail: function (record) {
      this.$refs.packageForm.edit(record)
      this.$refs.packageForm.title = '详情'
      this.$refs.packageForm.disableSubmit = true
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
